﻿var usageType = 'MCCH_UPLINK_USAGE';
var neid = '';
$(function (e) {
    neid = getValueOfURLParamter('neid');
    usageType = getValueOfURLParamter('type') == 'up' ? 'MCCH_UPLINK_USAGE' : 'MCCH_DOWNLINK_USAGE';
    GetData();
});

function GetData() {
  //  alert('刷新更新');
    $.ajax({
        type: "GET",
        url: 'TBSChannel.ashx',
        data: 'link=&top=20&neid=' + neid,
        success: function (dt) {
            if (dt && dt.rows && dt.rows.length > 0) {
                CreateFusionLineChart(dt);
            }
        },
        error: function (e) {

        }
    });
}
/*创建统计曲线*/
function CreateFusionLineChart(dt) {
    var myChart = new FusionCharts("../JS/FusionCharts/swf/MSLine.swf", "ChartId", "860", "400", "0", "0");
    myChart.setDataXML(setXML(dt));
    myChart.render("chartLine");
}
/*组装 XML*/
function setXML(dt) {
    var xmlStrCat = '<categories>';
    var xmlStr = '<dataset  renderAs="Line">';
    var ts = '';
    for (var length = dt.rows.length, i = length - 1; i >= 0; i--) {
        ts = dt.rows[i]['REPORT_TIMESTAMP'].split(' ')[1];
        xmlStr += ' <set label="' + ts + '" value="' + dt.rows[i][usageType] + '"';
        xmlStr += ' link=""  tooltext="时间：' + dt.rows[i]['REPORT_TIMESTAMP'] + '{br}占用率：' + dt.rows[i][usageType] + '%"/> ';
        xmlStrCat += ' <category label="' + ts + '" />';
    }

    xmlStr += '</dataset>';
    xmlStr += ' <styles>';
    xmlStr += ' <definition>';
    xmlStr += '        <style name="myCaptionFont" type="font" font="Arial" size="14" color="666666" bold="1"/>';
    xmlStr += '     </definition>';
    xmlStr += '     <application>';
    xmlStr += '        <apply toObject="Caption" styles="myCaptionFont" />';
    xmlStr += '     </application>';
    xmlStr += '   </styles>';
    xmlStr += '  </chart>';
    xmlStrCat += ' </categories>';

    var xmlStrTmp = '<chart caption="' + (dt.rows[0]['CHINA_NAME'] || '') + '主控信道' + (usageType == 'MCCH_UPLINK_USAGE' ? '上行' : '下行') + '占用率" canvasPadding="5" captionPadding="2" chartBottomMargin="10" animation="0" ';
    xmlStrTmp += '  showLegend="0"  showAboutMenuItem="1" showValues="0" bgColor="#E4F0FC" canvasBgAlpha="100" canvasBorderThickness="0" chartTopMargin ="5" chartLeftMargin="10" ';
    xmlStrTmp += ' >';

    return xmlStrTmp + xmlStrCat + xmlStr;
}

setInterval(GetData, 90000); //30秒更新一次数据